#!/usr/bin/env python

from agenda_class import Agenda

def _create_dataset ( start_point, lines, rows, tot_rows ):
        res = {}        
        
        count = 0
        for v in rows:
                v [ "_pos" ] = start_point + count
                res [ "row%d" % count ] = v
                count += 1
        
        res [ 'rows' ] = tot_rows
        res [ 'from_row' ] = start_point
        res [ 'to_row' ] = start_point + count
        res [ 'lines' ] = lines

        return res

def add_event ( liwe, id_evt = 0, id_cals = '', title = '', descr = '', visible = 0, uid = 0, created = 0, date_start = 0, date_end = 0, permalink = '', tags = '' ):
        """
        :INPUT:
                - id_evt:		SAFE_NUMBER
                - id_cals:		SAFE_STRING
                - title:		SAFE_STRING
                - descr:		SAFE_STRING
                - visible:		SAFE_NUMBER
                - uid:			SAFE_NUMBER
                - created:		SAFE_DATE
                - date_start:		SAFE_DATE
                - date_end:		SAFE_DATE
                - permalink:		SAFE_STRING
                - tags:			SAFE_STRING
        """

	a = Agenda ( liwe )
	
	id_evt = a.add_event ( id_evt = id_evt, id_cals = id_cals, title = title, descr = descr, visible = visible, uid = uid, created = created, date_start = date_start, date_end = date_end, permalink = permalink, tags = tags )

	return { 'id_evt' : id_evt }

def del_event ( liwe, id_evt = 0 ):
        """
        :INPUT:
                - id_evt:		SAFE_NUMBER
	"""
	a = Agenda ( liwe )	

	a.del_event ( id_evt = id_evt )

def add_calendar ( liwe, id_cal = 0, cal_name = '', uid = 0, gid = 0 ):
        """
        :INPUT:
                - id_cal:		SAFE_NUMBER
                - cal_name:		SAFE_STRING
                - uid:			SAFE_NUMBER
                - gid:			SAFE_NUMBER
        """

	a = Agenda ( liwe )

	id_cal = a.add_calendar ( id_cal = id_cal, cal_name = cal_name, uid = uid, gid = gid )
	return { 'id_cal' : id_cal }

def del_calendar ( liwe, id_cal = 0 ):
        """
        :INPUT:
                - id_cal:		SAFE_NUMBER
	"""
	
	a = Agenda ( liwe )

	a.del_calendar ( id_cal = id_cal )
